package com.andova;

import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.andova.sample.R;
import com.andova.view.Search;
import com.andova.view.SearchView;

import org.jetbrains.annotations.NotNull;

/**
 * Created by Administrator on 2018-05-07.
 *
 * @author kzaxil
 * @since 1.0.0
 */
public class SearchViewActivity extends AppCompatActivity implements Search.OnSearchListener {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_search_view);
        ((SearchView) findViewById(R.id.searchView)).setOnSearchListener(new SearchView.OnSearchListener() {
            @Override
            public void search(String s) {
                Toast.makeText(SearchViewActivity.this, s, Toast.LENGTH_SHORT).show();
            }
        });
        ((Search) findViewById(R.id.search)).setOnSearchListener(this);
        ((SeekBar) findViewById(R.id.sb_progress)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                float percent = progress / 100f;
                ((SearchView) findViewById(R.id.searchView)).collapse(percent);
                ((Search) findViewById(R.id.search)).collapse(percent);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

    public void collapse(View view) {
//        ((SearchView) findViewById(R.id.searchView)).collapse();
        ((Search) findViewById(R.id.search)).collapse();
    }

    public void expand(View view) {
//        ((SearchView) findViewById(R.id.searchView)).expand();
        ((Search) findViewById(R.id.search)).expand();
    }

    public void refresh(View view) {
//        findViewById(R.id.searchView).requestLayout();
        findViewById(R.id.search).requestLayout();
    }

    @Override
    public void search(@NotNull String s) {
        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
    }
}
